// 有错误

#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    map<int, vector<string>> mp;
    int N, K;
    cin >> N >> K;

    string name;
    int n, course;
    for (int i = 0; i < N; i++)
    {
        cin >> name >> n;
        for (int j = 0; j < n; j++)
        {
            cin >> course;
            mp[course].push_back(name);
        }
    }

    int i = 0;
    map<int, vector<string>>::iterator m = mp.begin();
    for (; i < K && m != mp.end(); i++, m++)
    {
        if(m->first <= 0 || m->first > K)
        {
            continue;
        }
        if(mp[m->first].size() == 0)
        {
            cout << m->first << ' ' << '0' << endl;
            continue;
        }
        cout << m->first << ' ' << mp[m->first].size() << endl;
        sort(mp[m->first].begin(), mp[m->first].end());
        for (int j = 0; j < mp[m->first].size(); j++)
        {
            cout << mp[m->first][j] << endl;
        }
    }

    return 0;
}